home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / freeware / pixeltoolbox / Setup.exe / Main / PixelToolbox.exe / PixelToolbox.dxr / Scripts_82_HSL script.ls < prev    next >
Encoding:
Text File  |  2002-06-08  |  5.9 KB  |  221 lines

  1. property pMySprite, pHSLField, pFieldLimit
  2. global gCast, gSize, gFirstColor, gSecondColor, gWvBgColor, gWvBgShadow, gWvVcolor, gWvVShadow, gWvHcolor, gWvHShadow, gHSL, gCurrentHSL, gTargetHSLColor, gHue, gSat, gLight, gRed, gGreen, gBlue
  3.  
  4. on beginSprite me
  5.   pMySprite = sprite(me.spriteNum)
  6. end
  7.  
  8. on mouseEnter me
  9.   if gHSL <> VOID then
  10.     put "Click and drag to adjust the " & pHSLField.word[1] & "." into field "status"
  11.   end if
  12. end
  13.  
  14. on mouseDown me
  15.   sliderHSL(me)
  16. end
  17.  
  18. on mouseLeave me
  19.   if gHSL <> VOID then
  20.     put EMPTY into field "status"
  21.   end if
  22. end
  23.  
  24. on resetHSLSlider
  25.   put 0 into field "Hue status"
  26.   put 0 into field "Saturation status"
  27.   put 0 into field "Lightness status"
  28.   sprite(189).locH = sprite(279).left
  29.   sprite(190).locH = sprite(279).left
  30.   sprite(191).locH = sprite(279).left
  31. end
  32.  
  33. on sliderHSL newloch
  34.   if gHSL <> VOID then
  35.     gCurrentHSL = duplicate(gHSL)
  36.     repeat while the mouseDown
  37.       newloch = the mouseH
  38.       if newloch < (sprite(278).left - 1) then
  39.         newloch = sprite(278).left - 1
  40.       end if
  41.       if newloch > sprite(279).right then
  42.         newloch = sprite(279).right
  43.       end if
  44.       pMySprite.locH = newloch
  45.       put integer((newloch - sprite(279).left) / 100.0 * pFieldLimit) into field pHSLField
  46.       updateStage()
  47.     end repeat
  48.     cursor(4)
  49.     updateHSL()
  50.     cursor(0)
  51.     gCurrentHSL = VOID
  52.   else
  53.     beep()
  54.     pass()
  55.   end if
  56. end
  57.  
  58. on updateHSL
  59.   repeat with Y = 0 to integer(gSize) - 1
  60.     repeat with X = 0 to integer(gSize) - 1
  61.       gTargetHSLColor = gHSL.getPixel(X, Y)
  62.       calculateHSL()
  63.       gHue = gHue + integer(the text of field "Hue status")
  64.       if gHue < 0 then
  65.         gHue = gHue + 360
  66.       else
  67.         if gHue >= 360 then
  68.           gHue = gHue - 360
  69.         end if
  70.       end if
  71.       if integer(the text of field "Saturation status") >= 0 then
  72.         satStep = (100 - gSat) / 100.0
  73.         gSat = integer(gSat + (integer(the text of field "Saturation status") * satStep))
  74.       else
  75.         satStep = (0 - gSat) / 100.0
  76.         gSat = integer(gSat - (integer(the text of field "Saturation status") * satStep))
  77.       end if
  78.       if integer(the text of field "Lightness status") >= 0 then
  79.         lightStep = (100 - gLight) / 100.0
  80.         gLight = integer(gLight + (integer(the text of field "Lightness status") * lightStep))
  81.       else
  82.         lightStep = (0 - gLight) / 100.0
  83.         gLight = integer(gLight - (integer(the text of field "Lightness status") * lightStep))
  84.       end if
  85.       calculateRGB()
  86.       gCurrentHSL.setPixel(X, Y, rgb(gRed, gGreen, gBlue))
  87.     end repeat
  88.   end repeat
  89.   member("adj hsl - " & gSize, gCast).image.copyPixels(gCurrentHSL, member("adj hsl - " & gSize, gCast).rect, gCurrentHSL.rect)
  90.   updateStage()
  91. end
  92.  
  93. on calculateHSL
  94.   pRed = gTargetHSLColor.red / 255.0
  95.   pGreen = gTargetHSLColor.green / 255.0
  96.   pBlue = gTargetHSLColor.blue / 255.0
  97.   pMin = min(pRed, pGreen, pBlue)
  98.   pMax = max(pRed, pGreen, pBlue)
  99.   pDelta = pMax - pMin
  100.   gLight = (pMax + pMin) / 2
  101.   if pMax = pMin then
  102.     gSat = 0
  103.     gHue = 0
  104.   else
  105.     if gLight <= 0.5 then
  106.       gSat = pDelta / (pMax + pMin)
  107.     else
  108.       gSat = pDelta / (2 - pMax - pMin)
  109.     end if
  110.     if pRed = pMax then
  111.       gHue = (pGreen - pBlue) / pDelta
  112.     else
  113.       if pGreen = pMax then
  114.         gHue = 2 + ((pBlue - pRed) / pDelta)
  115.       else
  116.         if pBlue = pMax then
  117.           gHue = 4 + ((pRed - pGreen) / pDelta)
  118.         end if
  119.       end if
  120.     end if
  121.   end if
  122.   gHue = integer(gHue * 359 / 6)
  123.   if gHue < 0 then
  124.     gHue = gHue + 360
  125.   else
  126.     if gHue >= 360 then
  127.       gHue = gHue - 360
  128.     end if
  129.   end if
  130.   gSat = integer(gSat * 100)
  131.   gLight = integer(gLight * 100)
  132. end
  133.  
  134. on calculateRGB
  135.   pHue = gHue / 360.0
  136.   pSat = gSat / 100.0
  137.   pLight = gLight / 100.0
  138.   if pSat = 0 then
  139.     gRed = integer(pLight * 255)
  140.     gGreen = integer(pLight * 255)
  141.     gBlue = integer(pLight * 255)
  142.   else
  143.     if pLight <= 0.5 then
  144.       temp2 = pLight * (1 + pSat)
  145.     else
  146.       temp2 = pLight + pSat - (pLight * pSat)
  147.     end if
  148.     temp1 = (2 * pLight) - temp2
  149.     tempRed = pHue + 0.33329999999999999
  150.     if tempRed < 0 then
  151.       tempRed = tempRed + 1.0
  152.     end if
  153.     if tempRed > 1 then
  154.       tempRed = tempRed - 1.0
  155.     end if
  156.     if (6 * tempRed) < 1 then
  157.       tempRed = temp1 + ((temp2 - temp1) * 6 * tempRed)
  158.     else
  159.       if (2 * tempRed) < 1 then
  160.         tempRed = temp2
  161.       else
  162.         if (3 * tempRed) < 2 then
  163.           tempRed = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempRed) * 6)
  164.         else
  165.           tempRed = temp1
  166.         end if
  167.       end if
  168.     end if
  169.     tempGreen = pHue
  170.     if tempGreen < 0 then
  171.       tempGreen = tempGreen + 1.0
  172.     end if
  173.     if tempGreen > 1 then
  174.       tempGreen = tempGreen - 1.0
  175.     end if
  176.     if (6 * tempGreen) < 1 then
  177.       tempGreen = temp1 + ((temp2 - temp1) * 6 * tempGreen)
  178.     else
  179.       if (2 * tempGreen) < 1 then
  180.         tempGreen = temp2
  181.       else
  182.         if (3 * tempGreen) < 2 then
  183.           tempGreen = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempGreen) * 6)
  184.         else
  185.           tempGreen = temp1
  186.         end if
  187.       end if
  188.     end if
  189.     tempBlue = pHue - 0.33329999999999999
  190.     if tempBlue < 0 then
  191.       tempBlue = tempBlue + 1.0
  192.     end if
  193.     if tempBlue > 1 then
  194.       tempBlue = tempBlue - 1.0
  195.     end if
  196.     if (6 * tempBlue) < 1 then
  197.       tempBlue = temp1 + ((temp2 - temp1) * 6 * tempBlue)
  198.     else
  199.       if (2 * tempBlue) < 1 then
  200.         tempBlue = temp2
  201.       else
  202.         if (3 * tempBlue) < 2 then
  203.           tempBlue = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempBlue) * 6)
  204.         else
  205.           tempBlue = temp1
  206.         end if
  207.       end if
  208.     end if
  209.     gRed = integer(tempRed * 255)
  210.     gGreen = integer(tempGreen * 255)
  211.     gBlue = integer(tempBlue * 255)
  212.   end if
  213. end
  214.  
  215. on getPropertyDescriptionList me
  216.   list = [:]
  217.   addProp(list, #pHSLField, [#comment: "Field Member Name.", #format: #string, #default: "Hue status"])
  218.   addProp(list, #pFieldLimit, [#comment: "Total field range.", #format: #integer, #default: 200])
  219.   return list
  220. end
  221.